<%--
  Created by IntelliJ IDEA.
  User: tum0r
  Date: 2019-03-13
  Time: 14:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="util.Decode" %>
<%@ page import="net.sf.json.JSONObject" %>
<%@ page import="net.sf.json.JSONArray" %>
<%@ page import="server.*" %>
<%@ page import="util.Encode" %>
<%@ page import="java.util.LinkedHashMap" %>
<%@ page import="config.ApplicationConfig" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    LinkedHashMap<String, String> pageConfig = ApplicationConfig.readConfig("page.json");
    request.setCharacterEncoding(pageConfig.get("encode"));
    response.setCharacterEncoding(pageConfig.get("encode"));
    Object user = session.getAttribute("user");
%>
<html>
<head>
    <title>代码详情</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/page.css">
    <link rel="stylesheet" href="css/code.css">
    <link rel="stylesheet" href="css/highlight/default.css">
</head>
<body>
<nav class="navbar navbar-inverse head" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse"
                    data-target="#navbar">
                <span class="sr-only">切换导航</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <%
                SettingServer settingServer = new SettingServer();
                settingServer.open();
                JSONObject logo = settingServer.readSettingObject("logo");
                if (logo.getString("logo").equals("")) {
            %>
            <img class="navbar-brand" src="image/logo.png">
            <%
            } else {
                FileServer fileServer = new FileServer();
                fileServer.open();
            %>
            <img class="navbar-brand" src="<%=fileServer.getImage(logo.getString("logo"))%>">
            <%
                    fileServer.close();
                }
            %>
            <a class="navbar-brand" href="#"><%=logo.getString("name")%>
            </a>
        </div>
        <div class="collapse navbar-collapse" id="navbar">
            <ul class="nav navbar-nav">
                <li>
                    <a href="index.jsp">首 页</a>
                </li>
                <li>
                    <a href="game.jsp">比 赛</a>
                </li>
                <li>
                    <a href="rank.jsp">排 名</a>
                </li>
                <li>
                    <a href="about.jsp">通 知</a>
                </li>
            </ul>
            <ul class="nav navbar-nav navbar-right text-center">
                <%
                    LoginServer loginServer = new LoginServer();
                    loginServer.open();
                    Object cookie = session.getAttribute("cookie");
                    if (user == null || user.toString().equals("") || cookie == null || cookie.toString().equals("") || loginServer.checkLogin(user.toString(), cookie.toString())) {
                        session.removeAttribute("user");
                        session.removeAttribute("cookie");
                        session.setAttribute("infoTitle", "未登录");
                        session.setAttribute("infoContent", "您还未登录，请先登录");
                        session.setAttribute("return", "index.jsp");
                        session.setAttribute("panelColor", "red");
                        loginServer.close();
                        response.sendRedirect("information.jsp");
                    } else {
                        loginServer.updateLoginTime(user.toString());
                        loginServer.close();
                %>
                <li>
                    <a href="mine" class="glyphicon glyphicon-user active">&nbsp;<%=user%>
                    </a>
                </li>
                <li>
                    <a href="#" class="glyphicon glyphicon-log-out" data-toggle="modal"
                       data-target="#logout">&nbsp;退出</a>
                    <div class="modal fade" id="logout" role="dialog" aria-hidden="true"
                         aria-labelledby="logoutLabel">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"
                                            onclick="input_clear(document.getElementById('logout_form'))">&times;
                                    </button>
                                    <h4 class="modal-title" id="logoutLabel">退 出 登 录</h4>
                                </div>
                                <div class="modal-body">
                                    确定要退出吗？
                                    <form id="logout_form" action="logout" method="post">
                                        <input type="text" name="username" hidden="hidden" value="<%=user%>">
                                    </form>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-primary"
                                            onclick="form_submit(document.getElementById('logout_form'))">&nbsp;退出
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </li>
                <%
                    }
                %>
            </ul>
        </div>
    </div>
</nav>

<div class="container main">
    <%
        String recordID = request.getParameter("recordID");
        Decode decode = new Decode();
        if (recordID != null && !recordID.equals("")) {
            GameServer gameServer = new GameServer();
            gameServer.open();
            JSONObject result = gameServer.getRecordCode(recordID);
            if (result.size() != 0) {
    %>
    <div class="col-sm-4">
        <row>
            <div class="panel panel-success col-sm-12">
                <div class="panel-heading text-center">
                    <h2 class="panel-title">提交信息</h2>
                </div>
                <div class="panel-body">
                    <table class="table table-striped text-center">
                        <tr>
                            <td>队伍名</td>
                            <td><%=result.getString("user")%>
                            </td>
                        </tr>
                        <tr>
                            <td>真实姓名</td>
                            <td><%=result.getString("real_name")%>
                            </td>
                        </tr>
                        <tr>
                            <td>性别</td>
                            <td><%=result.getString("sex")%>
                            </td>
                        </tr>
                        <tr>
                            <td>语言</td>
                            <td><%=result.getString("language")%>
                            </td>
                        </tr>
                        <tr>
                            <td>结果</td>
                            <td>
                                <%
                                    String submitResult = result.getString("result");
                                    if (submitResult.equals("Accepted")) {
                                %>
                                <span class="btn btn-success"><%=submitResult%></span>
                                <%
                                } else if (submitResult.equals("Compilation Error") || submitResult.equals("Time Limit Exceeded") || submitResult.equals("Memory Limit Exceeded") || submitResult.equals("Presentation Error")) {
                                %>
                                <span class="btn btn-warning"><%=submitResult%></span>
                                <%
                                } else if (submitResult.equals("Compile...") || submitResult.equals("Running...")) {
                                %>
                                <span class="btn btn-info"><%=submitResult%></span>
                                <%
                                } else if (submitResult.equals("RunTime Error")) {
                                %>
                                <span class="btn btn-primary"><%=submitResult%></span>
                                <%
                                } else {
                                %>
                                <span class="btn btn-danger"><%=submitResult%></span>
                                <%
                                    }
                                %>
                            </td>
                        </tr>
                        <tr>
                            <td>时间</td>
                            <td><%=result.getString("time")%> ms
                            </td>
                        </tr>
                        <tr>
                            <td>内存</td>
                            <td><%=result.getString("memory")%> kb
                            </td>
                        </tr>
                        <tr>
                            <td>提交时间</td>
                            <td><%=result.getString("submit_time")%>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </row>
        <row>
            <div class="panel panel-warning col-sm-12">
                <div class="panel-heading text-center">
                    <h2 class="panel-title"><%=decode.languageDecode(result.getString("title"))%>
                    </h2>
                </div>
                <div class="panel-body subject_content">
                    <%=decode.languageDecode(result.getString("content")).replace("\r", "<br>")%>
                    <br>
                </div>
            </div>
        </row>
    </div>
    <div class="col-sm-8">
        <row>
            <div class="panel panel-info col-sm-12">
                <div class="panel-heading text-center">
                    <h2 class="panel-title">代码</h2>
                </div>
                <div class="panel-body">
                    <pre>
                        <%
                            Encode encode = new Encode();
                        %>
                        <code class="code_content java text-left"><%=encode.utf8Encode(encode.utf8EncodeSpecial(result.getString("code")))%></code>
                    </pre>
                </div>
            </div>
        </row>
    </div>
    <%
            }
            gameServer.close();
        }
    %>
</div>

<%
    JSONArray foot = settingServer.readSettingArray("foot");
    JSONObject foot0 = foot.getJSONObject(0);
    JSONObject foot1 = foot.getJSONObject(1);
    JSONObject foot2 = foot.getJSONObject(2);
%>
<div class="foot">
    <row>
        <div class="col-xs-4 col-sm-4">
            <br>
            <div class="foot_item_title">
                <p><%=decode.utf8Decode(foot0.getString("title"))%>
                </p>
            </div>
            <hr class="foot_split">
            <div class="foot_item">
                <p><%=decode.utf8Decode(foot0.getString("line0"))%>
                </p>
                <p><%=decode.utf8Decode(foot0.getString("line1"))%>
                </p>
                <p><%=decode.utf8Decode(foot0.getString("line2"))%>
                </p>
            </div>
        </div>
        <div class="col-xs-4 col-sm-4">
            <br>
            <div class="foot_item_title">
                <p><%=decode.utf8Decode(foot1.getString("title"))%>
                </p>
            </div>
            <hr class="foot_split">
            <div class="foot_item">
                <p><%=decode.utf8Decode(foot1.getString("line0"))%>
                </p>
                <p><%=decode.utf8Decode(foot1.getString("line1"))%>
                </p>
                <p><%=decode.utf8Decode(foot1.getString("line2"))%>
                </p>
            </div>
        </div>
        <div class="col-xs-4 col-sm-4">
            <br>
            <div class="foot_item_title">
                <p><%=decode.utf8Decode(foot2.getString("title"))%>
                </p>
            </div>
            <hr class="foot_split">
            <div class="foot_item">
                <p><%=decode.utf8Decode(foot2.getString("line0"))%>
                </p>
                <p><%=decode.utf8Decode(foot2.getString("line1"))%>
                </p>
                <p><%=decode.utf8Decode(foot2.getString("line2"))%>
                </p>
            </div>
        </div>
    </row>
</div>
<%
    settingServer.close();
%>
</body>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/page.js"></script>
<script src="js/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</html>
